package com.tongjie.hotelbooking.role.entity;

import com.tongjie.hotelbooking.authority.entity.Authority;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "hb_role")
public class Role implements Serializable {

    private static final long serialVersionUID = 4105415367835780584L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column
    private String roleName;

    @Column
    private String roleCode;

    @Column
    private String description;

    @ManyToMany(cascade = {CascadeType.ALL})
    @JoinTable(name = "hb_role_authority", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "authority_id"))
    private List<Authority> authorities = new ArrayList<>();

}
